//封装图表bar组件
import React, {useEffect, useRef} from 'react';
import * as echarts from "echarts";

const Bar = ({title, xData, yData, style}) => {
    const demoRef = useRef()
    const chartInit = () => {
        const myChart = echarts.init(demoRef.current);
        // 绘制图表
        myChart.setOption({
            title: {
                text: title
            },
            tooltip: {},
            xAxis: {
                data: xData
            },
            yAxis: {},
            series: [
                {
                    name: '销量',
                    type: 'bar',
                    data:yData
                }
            ]
        });
    }

    //执行初始化的函数
    useEffect(() => {
        chartInit()
    }, [])
    return <div>
        <div ref={demoRef} style={style}></div>
    </div>
};

export default Bar;